//
//  AppDelegate.m
//  PageViewControllerDemo
//
//  Created by apple on 15/9/24.
//  Copyright © 2015年 戴维营教育. All rights reserved.
//

#import "AppDelegate.h"

#import "FirstViewController.h"
#import "SecondViewController.h"

@interface AppDelegate () <UIPageViewControllerDataSource>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    
    //1. 创建分页控制器
    UIPageViewController *pageCtrl = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    //2. 设置数据源代理
    pageCtrl.dataSource = self;
    
    FirstViewController *firstCtrl = [FirstViewController new];
    //3. 设置当前可见页面
    [pageCtrl setViewControllers:@[firstCtrl] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
    
    self.window.rootViewController = pageCtrl;
    
    return YES;
}

#pragma mark - UIPageViewControllerDataSource
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
    SecondViewController *secondCtrl = [SecondViewController new];
    return secondCtrl;
}

- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    FirstViewController *firstCtrl = [FirstViewController new];
    return firstCtrl;
}
@end
